//
//  RABleUtil.m
//  RAFSUManagement
//
//  Created by Piccolo on 22/03/2018.
//  Copyright © 2018 Rayonics. All rights reserved.
//

#import "RABleUtil.h"

@implementation RABleUtil

+ (NSRAPeripheralType)peripheralTypeFromName:(NSString *)name {
    if (!name || [name isEqualToString:@""]) {
        return NO;
    }
    if (IS_SIMPLE_FSU(name)){
        return NSRAPeripheralTypeSimpleFSU;
    } else if (IS_GENERAL_FSU(name)) {
        return NSRAPeripheralTypeGeneralFSU;
    } else {
        return NSRAPeripheralTypeUnknow;
    }
}

+ (BOOL)bluetoothIsOn {
    return RABleServiceController.sharedManager.bluetoothIsOn;
}

+ (void)stopScanAndInitSDKFromPeripheral:(RAFSUSDKPeripheral *)sdkPeripheral {
    
    [RABleServiceController.sharedManager stopScan];
    RABleServiceController.sharedManager.peripheral = sdkPeripheral.peripheral;
    if (IS_SIMPLE_FSU(sdkPeripheral.peripheralName)) {
        [RABleServiceController.sharedManager initSimpleFSUSDK];
    } else if (IS_GENERAL_FSU(sdkPeripheral.peripheralName)) {
        [RABleServiceController.sharedManager initGeneralFSUSDK];
    }
}

+ (void)disconnectBle {
    
    [RABleServiceController.sharedManager disconnectBle];
}

+ (BOOL)bluetoothIsConnected {
    
    return RABleServiceController.sharedManager.currentBleState == CBPeripheralStateConnected;
}

+ (BOOL)bleArray:(NSArray <RAFSUSDKPeripheral *>*)bleArray containsPeripheral:(RAFSUSDKPeripheral *)fsuSDKPeripheral {
    
    for (RAFSUSDKPeripheral *tempFSUPeripheral in bleArray) {
        if (tempFSUPeripheral.peripheral == fsuSDKPeripheral.peripheral) {
            return YES;
        }
    }
    return NO;
}
@end
